package src.A_JavaBase;

public class Demo09 {
    public static void main(String[] args) {
        //冒泡排序，每一轮比较都会产出一个最大或者最小的数字，下一轮则少一次排序
        //升序
        int[] arr = {6,2,10,4,8,2,2,2};
        int min = 0;
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = i+1; j < arr.length; j++) {
                if (arr[j] < arr[i]){
                    min = arr[j];
                    arr[j] = arr[i];
                    arr[i] = min;
                }
            }
        }
        for (int i : arr){
            System.out.print(i+" ");
        }
        System.out.println();
        //降序
        int[] arr2 = {6,2,10,4,8,2,2,2};
        int max = 0;
        for (int i = 0; i < arr2.length-1; i++) {
            for (int j = i+1; j < arr2.length; j++) {
                if (arr2[j] > arr2[i]){
                    max = arr2[j];
                    arr2[j] = arr2[i];
                    arr2[i] = max;
                }
            }
        }
        for (int i : arr2){
            System.out.print(i+" ");
        }

    }
}
